home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4359 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: news.iag.net!news
  2. From: jatmon@iag.net (John R Buchan)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: simple code, argc, argv, strcmp()
  5. Date: 3 Feb 1996 23:37:27 GMT
  6. Organization: Internet Access Group, Orlando, Florida
  7. Message-ID: <4f0rjn$sfh@news.iag.net>
  8. References: <11f7cc$17261a.3b3@daprez> <4etj7c$bma@news.iag.net> <fcusack-0202961621470001@mudskipper.cac.psu.edu>
  9. NNTP-Posting-Host: pm1-orl12.iag.net
  10. X-Newsreader: WinVN 0.99.7
  11.  
  12. In article <fcusack-0202961621470001@mudskipper.cac.psu.edu>, fcusack@tdx.org 
  13. says...
  14. >
  15. >In article <4etj7c$bma@news.iag.net>, jatmon@iag.net (John R Buchan) wrote:
  16. >
  17. >> In article <11f7cc$17261a.3b3@daprez>, otisg@panther.middlebury.edu says...
  18. >> >
  19. <snip>
  20. >> >int main (int argc, char **argv) {
  21. >> >
  22. >> >  void Usage   (void);
  23. >> >  void Encode (int, char **);
  24. >> >  void Decode (int, char **);
  25. >> >
  26. >> >  if (!strcmp(argv[1],"-d") || !strcmp(argv[1],"-e")) {
  27. >> >    Usage();
  28. >> >  }
  29. >> <snip>
  30. >> 
  31. >> I assume you mean this to call Usage if argv[1] is not "-e" and not "-d"?
  32. >> Change the || to &&.  
  33. >
  34. >The && test would _never_ pass. argv[1] could never be both "-d" and "-e".
  35.  
  36. You are correct, of course.  Stupidity on my part. I tend to get careless 
  37. about strcmp's reverse logic (ie returns False, when the strings match), when
  38. I am not paying attention (not an excuse, just an explanation).  I normally 
  39. compare the return value to 0, just to keep myself straight.  
  40.  
  41. >The || is correct here.
  42. <snip>
  43.  
  44. ?? This would mean calling Usage for a correct first argument ("-e" or "-d"
  45. instead of an incorrect one.  How about:
  46.  
  47.   if ( strcmp(argv[1],"-d") && strcmp(argv[1],"-e") ) 
  48.  
  49. /* if contents of argv[1] is not "-d" and contents of argv[1] is not "-e" */
  50.  
  51.  
  52. I do apologize for the error.  Thanks for pointing it out.
  53.  
  54. -- 
  55. John R Buchan           -:|:-     Looking for that elusive FAQ?  ftp to:
  56. jatmon@mail.iag.net     -:|:-     rtfm.mit.edu /pub/usenet-by-group/....
  57.  
  58.